package com.ruoyi.web.controller.user;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbFaceoryUser;
import com.ruoyi.system.service.ITbFaceoryUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户单位列Controller
 * 
 * @author ruoyi
 * @date 2020-06-24
 */
@Controller
@RequestMapping("/user/factoryuser")
public class TbFaceoryUserController extends BaseController
{
    private String prefix = "user/factoryuser";

    @Autowired
    private ITbFaceoryUserService tbFaceoryUserService;

    @RequiresPermissions("user:factoryuser:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/factoryuser";
    }

    /**
     * 查询客户单位列列表
     */
    @RequiresPermissions("user:factoryuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbFaceoryUser tbFaceoryUser)
    {
        startPage();
        List<TbFaceoryUser> list = tbFaceoryUserService.selectTbFaceoryUserList(tbFaceoryUser);
        return getDataTable(list);
    }

    /**
     * 导出客户单位列列表
     */
    @RequiresPermissions("user:user:export")
    @Log(title = "客户单位列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbFaceoryUser tbFaceoryUser)
    {
        List<TbFaceoryUser> list = tbFaceoryUserService.selectTbFaceoryUserList(tbFaceoryUser);
        ExcelUtil<TbFaceoryUser> util = new ExcelUtil<TbFaceoryUser>(TbFaceoryUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增客户单位列
     */
    @GetMapping("/add")
    public String add()

    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户单位列
     */
    @RequiresPermissions("user:user:add")
    @Log(title = "客户单位列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbFaceoryUser tbFaceoryUser)
    {
        return toAjax(tbFaceoryUserService.insertTbFaceoryUser(tbFaceoryUser));
    }

    /**
     * 修改客户单位列
     */
    @GetMapping("/edit/{fid}")
    public String edit(@PathVariable("fid") Long fid, ModelMap mmap)
    {
        TbFaceoryUser tbFaceoryUser = tbFaceoryUserService.selectTbFaceoryUserById(fid);
        mmap.put("tbFaceoryUser", tbFaceoryUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户单位列
     */
    @RequiresPermissions("user:user:edit")
    @Log(title = "客户单位列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbFaceoryUser tbFaceoryUser)
    {
        return toAjax(tbFaceoryUserService.updateTbFaceoryUser(tbFaceoryUser));
    }

    /**
     * 删除客户单位列
     */
    @RequiresPermissions("user:user:remove")
    @Log(title = "客户单位列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {

        return toAjax(tbFaceoryUserService.deleteTbFaceoryUserByIds(ids));
    }
}
